<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="C++,Python," />










<meta name="description" content="通过 UML 类图表示类之间的关系.">
<meta name="keywords" content="C++,Python">
<meta property="og:type" content="article">
<meta property="og:title" content="UML 类图">
<meta property="og:url" content="https://zhaoyongcnsx.github.io/2018/10/05/UML 类图/index.html">
<meta property="og:site_name" content="zhaoyongCNSX Blogs">
<meta property="og:description" content="通过 UML 类图表示类之间的关系.">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/UMLguanxi.png">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/lei.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/neibulei.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/jiekou.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/fanhua.png">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/shixian1.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/shixian2.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/zhuhe.png">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/juhe.png">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/guanlian1.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/guanlian2.jpg">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/guanlian3.png">
<meta property="og:image" content="https://zhaoyongcnsx.github.io/res/mdImg/yilai.png">
<meta property="og:updated_time" content="2018-10-05T08:33:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="UML 类图">
<meta name="twitter:description" content="通过 UML 类图表示类之间的关系.">
<meta name="twitter:image" content="https://zhaoyongcnsx.github.io/res/mdImg/UMLguanxi.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"right","display":"hide","offset":12,"b2t":false,"scrollpercent":true,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://zhaoyongcnsx.github.io/2018/10/05/UML 类图/"/>





  <title>UML 类图 | zhaoyongCNSX Blogs</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">zhaoyongCNSX Blogs</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://zhaoyongcnsx.github.io/2018/10/05/UML 类图/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="zhaoyongCNSX">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/myLogo.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="zhaoyongCNSX Blogs">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">UML 类图</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-10-05T16:33:10+08:00">
                2018-10-05
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2018-10-05T16:33:10+08:00">
                2018-10-05
              </time>
            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/programming/" itemprop="url" rel="index">
                    <span itemprop="name">编程</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2018/10/05/UML 类图/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count gitment-comments-count" data-xid="/2018/10/05/UML 类图/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          
          
             <span id="/2018/10/05/UML 类图/" class="leancloud_visitors" data-flag-title="UML 类图">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  3
                </span>
              
            </div>
          

          
              <div class="post-description">
                  通过 UML 类图表示类之间的关系.
              </div>
          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <blockquote>
<p>友情提示: 你可以选择以下镜像网站进行阅读:</p>
<ul>
<li><a href="https://zhaoyongcnsx.github.io">GitHub Pages</a></li>
<li><a href="http://47.92.146.3" target="_blank" rel="noopener">国内个人站</a></li>
</ul>
</blockquote>
<h1 id="1-推荐网站"><a href="#1-推荐网站" class="headerlink" title="1. 推荐网站"></a>1. 推荐网站</h1><ul>
<li>UML 类图官方网站：<a href="http://www.uml.org.cn/oobject/201104212.asp" target="_blank" rel="noopener">http://www.uml.org.cn/oobject/201104212.asp</a></li>
<li>UML 类图中关系的总结：<a href="http://blog.csdn.net/dragonpeng2008/article/details/6836448" target="_blank" rel="noopener">http://blog.csdn.net/dragonpeng2008/article/details/6836448</a></li>
<li>开源的 UML 工具：<a href="http://www.iteye.com/news/11216-12-best-opensource-uml-tool" target="_blank" rel="noopener">http://www.iteye.com/news/11216-12-best-opensource-uml-tool</a></li>
<li>在线绘制 UML 类图：<a href="https://www.processon.com" target="_blank" rel="noopener">https://www.processon.com</a></li>
<li>类间关系：<a href="http://www.cnblogs.com/floodpeak/archive/2008/02/27/1083533.html" target="_blank" rel="noopener">http://www.cnblogs.com/floodpeak/archive/2008/02/27/1083533.html</a></li>
</ul>
<h1 id="2-概述"><a href="#2-概述" class="headerlink" title="2. 概述"></a>2. 概述</h1><blockquote>
<p>UML 类图是用于显示<strong>类</strong>, <strong>接口</strong>及它们之间的<strong>静态结构和关系</strong>的一种静态模型<br>速记：”泛，实，组，聚，关，依”. 泛化父类，实现接口，组合（生命期同), 聚合（生命期可不同), 关联，依赖（临时调用)<br>表示方法：泛化（实线空三角箭头), 实现（虚线空三角箭头), 组合（实菱形实线箭头), 聚合（空菱形实线箭头), 关联（实线箭头), 依赖（虚线箭头)</p>
</blockquote>
<p><img src="/res/mdImg/UMLguanxi.png" alt="UML"></p>
<h1 id="3-基本元素"><a href="#3-基本元素" class="headerlink" title="3. 基本元素"></a>3. 基本元素</h1><h2 id="3-1-类"><a href="#3-1-类" class="headerlink" title="3.1. 类"></a>3.1. 类</h2><ul>
<li>首行为<strong>类名</strong>. 类名为<em>斜体</em>表示该类为<strong>抽象类</strong>.</li>
<li>第二行为类的<strong>特性</strong>, 也就是<strong>字段</strong>或<strong>属性</strong>. 在之后添加<code>: 该属性的类型名</code>. eg: <code>name :string</code></li>
<li>第三行为类的<strong>操作</strong>, 也就是<strong>方法</strong>或<strong>行为</strong>. 在之后添加<code>: 返回值类型</code>. eg: <code>func(name :string, age :int) :bool</code></li>
<li><strong>特性</strong>和<strong>操作</strong>的访问限定符：<code>+</code>表示<code>public</code>; <code>-</code>表示<code>private</code>; <code>#</code>表示<code>protected</code></li>
</ul>
<p><img src="/res/mdImg/lei.jpg" alt="类"></p>
<h3 id="3-1-1-内部类"><a href="#3-1-1-内部类" class="headerlink" title="3.1.1. 内部类"></a>3.1.1. 内部类</h3><ul>
<li><code>Memento</code>为<code>DataConverter</code>的内部类<br><img src="/res/mdImg/neibulei.jpg" alt="内部类"></li>
</ul>
<h2 id="3-2-接口"><a href="#3-2-接口" class="headerlink" title="3.2. 接口"></a>3.2. 接口</h2><ul>
<li>首行为 &lt;<interface>&gt;和接口名称</interface></li>
<li>第二行为接口方法</li>
<li>如附件图所示</li>
</ul>
<p><img src="/res/mdImg/jiekou.jpg" alt="接口"></p>
<h1 id="4-类之间的关系"><a href="#4-类之间的关系" class="headerlink" title="4. 类之间的关系"></a>4. 类之间的关系</h1><p>类之间的关系只是在某个问题域内讨论才有效。</p>
<ul>
<li>纵向关系<ul>
<li>继承</li>
</ul>
</li>
<li>横向关系<ul>
<li>组合</li>
<li>聚合</li>
<li>关联</li>
<li>依赖</li>
</ul>
</li>
<li>关系的强弱顺序：泛化 = 实现 &gt; 组合 &gt; 聚合 &gt; 关联 &gt; 依赖</li>
</ul>
<h2 id="4-1-泛化-Generalization"><a href="#4-1-泛化-Generalization" class="headerlink" title="4.1. 泛化 (Generalization)"></a>4.1. 泛化 (Generalization)</h2><ul>
<li>也就是<strong>继承</strong>, <code>is-a</code>的关系，表示<em>一般</em>与<em>特殊</em>之间的关系。</li>
<li>表示：带三角箭头的实线，箭头指向父类</li>
<li>示例：如附件图所示。<code>Tiger</code>子类指向<code>Animal</code>父类</li>
</ul>
<p><img src="/res/mdImg/fanhua.png" alt="泛化"></p>
<h2 id="4-2-实现-Realization"><a href="#4-2-实现-Realization" class="headerlink" title="4.2. 实现 (Realization)"></a>4.2. 实现 (Realization)</h2><ul>
<li>表示<strong>实现接口</strong>， 接口的实现指向接口</li>
<li>表示：<ul>
<li>方法 1: 带三角箭头的虚线。实现类指向接口</li>
<li>方法 2: 棒棒糖表示法，圆圈部分为接口名称。</li>
</ul>
</li>
</ul>
<p><img src="/res/mdImg/shixian1.jpg" alt="实现 1"><br><img src="/res/mdImg/shixian2.jpg" alt="实现 2"></p>
<h2 id="4-3-关联"><a href="#4-3-关联" class="headerlink" title="4.3. 关联"></a>4.3. 关联</h2><p>用于表示对象之间的引用关系，常在<strong>类属性</strong>中出现。</p>
<ul>
<li><p>分类</p>
<ul>
<li>一般关联</li>
<li>聚合</li>
<li>组合</li>
</ul>
</li>
<li><p>多重性</p>
<ul>
<li>用于表示实例之间的引用个数的关系。</li>
<li>符号表：</li>
</ul>
</li>
</ul>
<table>
<thead>
<tr>
<th style="text-align:center">符号</th>
<th style="text-align:center">说明</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">1</td>
<td style="text-align:center">不超过一个</td>
</tr>
<tr>
<td style="text-align:center">0..1</td>
<td style="text-align:center">0 或 1 个</td>
</tr>
<tr>
<td style="text-align:center">*</td>
<td style="text-align:center">许多</td>
</tr>
<tr>
<td style="text-align:center">0..*</td>
<td style="text-align:center">0 或许多</td>
</tr>
<tr>
<td style="text-align:center">1..*</td>
<td style="text-align:center">1 或许多</td>
</tr>
</tbody>
</table>
<h3 id="4-3-1-组合-Composition"><a href="#4-3-1-组合-Composition" class="headerlink" title="4.3.1. 组合 (Composition)"></a>4.3.1. 组合 (Composition)</h3><ul>
<li>也称为<strong>合成</strong>.</li>
<li>一种<code>contains-a</code>的关系，也用来描述<strong>整体</strong>和<strong>部分</strong>的关系。</li>
<li>与聚合不同，其为强的关联关系。<strong>部分</strong>离开<strong>整体</strong>不可存在。两者<strong>生命周期一致</strong>.</li>
<li>表示：实心菱形指向整体，箭头可有可无。</li>
<li>示例：部门为公司的一部分，实心菱形由部门指向公司。<br><img src="/res/mdImg/zhuhe.png" alt="组合"></li>
</ul>
<h3 id="4-3-2-聚合-Aggregation"><a href="#4-3-2-聚合-Aggregation" class="headerlink" title="4.3.2. 聚合 (Aggregation)"></a>4.3.2. 聚合 (Aggregation)</h3><ul>
<li>一种<code>owns a</code>的关系。用来描述<strong>整体</strong>与<strong>部分</strong>关系，且部分可离开整体<strong>单独存在</strong>.</li>
<li>表示：空心菱形指向整体，箭头可有可无。</li>
<li>示例：一个汽车有一个引擎和四个轮胎<br><img src="/res/mdImg/juhe.png" alt="聚合"></li>
</ul>
<h3 id="4-3-3-一般关联-Association"><a href="#4-3-3-一般关联-Association" class="headerlink" title="4.3.3. 一般关联 (Association)"></a>4.3.3. 一般关联 (Association)</h3><ul>
<li>一种<code>has a</code>的关系。</li>
<li>表示：带普通箭头的实线，指向被拥有者。</li>
<li>可自身关联</li>
</ul>
<p><img src="/res/mdImg/guanlian1.jpg" alt="关联 1"><br><img src="/res/mdImg/guanlian2.jpg" alt="关联 2"><br><img src="/res/mdImg/guanlian3.png" alt="关联 3"></p>
<h2 id="4-4-依赖-Dependency"><a href="#4-4-依赖-Dependency" class="headerlink" title="4.4. 依赖 (Dependency)"></a>4.4. 依赖 (Dependency)</h2><ul>
<li>最弱的，临时性的关联。</li>
<li>一种<code>used a</code>关系。一个类的实现需要另一个类的协助。尽量避免双向依赖。</li>
<li>由<strong>局部变量</strong>, <strong>函数参数</strong>, <strong>静态方法</strong> 对于其他对象的<strong>调用</strong>关系。</li>
<li>表示：使用类 —&gt; 被依赖（被使用) 者</li>
<li>一旦被依赖的改变，则使用类必须改变。若使用类改变，和被依赖的无关。</li>
<li>示例：<br><code>Order</code>类依赖<code>DBUtil</code>类的<code>execute()</code>方法去做一些事情，一旦<code>DBUtil</code>改变，则<code>Order</code>必须改变。</li>
</ul>
<p><img src="/res/mdImg/yilai.png" alt="依赖"></p>
<!-- RES -->
<!-- RES -->
<blockquote>
<p>写在最后, 欢迎读者写下评论, 我们一起交流进步.</p>
</blockquote>

      
    </div>
    
    
    

    

    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    zhaoyongCNSX
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://zhaoyongcnsx.github.io/2018/10/05/UML 类图/" title="UML 类图">https://zhaoyongcnsx.github.io/2018/10/05/UML 类图/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/C/" rel="tag"># C++</a>
          
            <a href="/tags/Python/" rel="tag"># Python</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/10/05/Python 函数相关/" rel="prev" title="Python 函数相关">
                Python 函数相关 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      
        <div onclick="showGitment()" id="gitment-display-button">显示 Gitment 评论</div>
        <div id="gitment-container" style="display:none"></div>
      
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/myLogo.png"
                alt="zhaoyongCNSX" />
            
              <p class="site-author-name" itemprop="name">zhaoyongCNSX</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">2</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/zhaoyongCNSX" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:zhaoyongCNSX@163.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="http://47.92.146.3" target="_blank" title="Self">
                      
                        <i class="fa fa-fw fa-globe"></i>Self</a>
                  </span>
                
            </div>
          

          
          
            <div class="cc-license motion-element" itemprop="license">
              <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
                <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
              </a>
            </div>
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-推荐网站"><span class="nav-text">1. 推荐网站</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#2-概述"><span class="nav-text">2. 概述</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#3-基本元素"><span class="nav-text">3. 基本元素</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#3-1-类"><span class="nav-text">3.1. 类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-1-内部类"><span class="nav-text">3.1.1. 内部类</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-2-接口"><span class="nav-text">3.2. 接口</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#4-类之间的关系"><span class="nav-text">4. 类之间的关系</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-泛化-Generalization"><span class="nav-text">4.1. 泛化 (Generalization)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-实现-Realization"><span class="nav-text">4.2. 实现 (Realization)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-3-关联"><span class="nav-text">4.3. 关联</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-1-组合-Composition"><span class="nav-text">4.3.1. 组合 (Composition)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-2-聚合-Aggregation"><span class="nav-text">4.3.2. 聚合 (Aggregation)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-3-一般关联-Association"><span class="nav-text">4.3.3. 一般关联 (Association)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-4-依赖-Dependency"><span class="nav-text">4.4. 依赖 (Dependency)</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2017 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">zhaoyongCNSX</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">7.6k</span>
  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
          <span id="scrollpercent"><span>0</span>%</span>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  








  
  





  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/three.min.js"></script>
  

  
  
    <script type="text/javascript" src="/lib/three/canvas_sphere.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  







<!-- LOCAL: You can save these files to your site and update links -->
    
        
        <link rel="stylesheet" href="https://aimingoo.github.io/gitmint/style/default.css">
        <script src="https://aimingoo.github.io/gitmint/dist/gitmint.browser.js"></script>
    
<!-- END LOCAL -->

    

    
      <script type="text/javascript">
      function renderGitment(){
        var gitment = new Gitmint({
            id: window.location.pathname, 
            owner: 'zhaoyongCNSX@163.com',
            repo: 'blogs',
            
            lang: "" || navigator.language || navigator.systemLanguage || navigator.userLanguage,
            
            oauth: {
            
            
                client_secret: 'b00a50e88366c64af5b8772b1206047aa7b3ec3b',
            
                client_id: 'cc6ed49c5b86432240d3'
            }});
        gitment.render('gitment-container');
      }

      
      function showGitment(){
        document.getElementById("gitment-display-button").style.display = "none";
        document.getElementById("gitment-container").style.display = "block";
        renderGitment();
      }
      
      </script>
    







  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("TDDsUDe2bNJ9AuDLtdMqfUNo-gzGzoHsz", "0RHypA7igWU0QbMnfRg9D6DU");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  

  

  

  

</body>
</html>
